package com.garen.fire.dao.impl;

import com.garen.fire.dao.IFireCaseRecordDao;
import com.garen.fire.entity.FireCaseRecord;
import com.garen.utils.MapBuilder;
import com.garen.common.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;


@Repository
public class FireCaseRecordDaoImpl extends BaseDao<FireCaseRecord> implements IFireCaseRecordDao {

	@PostConstruct
	private void init(){
		initOrm(FireCaseRecord.class);
	}

	//获取案情信息
	@Override
	public List<FireCaseRecord> getFireCaseRecordList(String ajbh,String orgId){
		String sql = "select r.record_id,r.fire_car,u.user_name as fire_man_name,u.user_id as fire_man,"
				+ " (year(now())-year(u.user_birthday)-1) + ( DATE_FORMAT(u.user_birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') ) as fire_man_age ,"
				+ " (select code_name from fire_code t1 where t1.code_type = '5' and code_value=u.user_police_rank) as fire_police_rank "
					+ " from fire_user u left join fire_case_record r on  r.fire_man = u.user_id"
					+ " and r.fire_ajbh = :ajbh "
					+ " where u.user_org_id = :orgId ";
		
		 Map<String,Object> paramMap = new MapBuilder()
				 .put("ajbh",ajbh)
				 .put("orgId",orgId)
				 .build();
		return getListBySQL(sql, paramMap);
	}
	
	//获取案情信息
	public List<FireCaseRecord> getFireCaseRecordList1(String ajbh){
		String sql = "select u.user_name as fire_man_name,c.car_num as fire_car_name ,"
				+ "c.car_uuid as fire_car_uuid,o.org_short_name as fire_org_name,"
				+ " o.org_lat as fire_gps_lat,o.org_lng as fire_gps_lng,r.* "
					+ " from fire_case_record r,fire_user u,fire_car c,fire_org o "
					+ " where r.fire_ajbh = :ajbh and u.user_id = r.fire_man and r.fire_car = c.car_id and r.fire_org = o.org_id "
					+ " order by r.fire_org desc ,r.fire_car desc ,r.fire_man desc ";
		 Map<String,Object> paramMap = new MapBuilder()
				 .put("ajbh",ajbh)
				 .build();
		return getListBySQL(sql, paramMap);
	}
		
		

}
